package guoanmaker.operator.business.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.OperatorHeadline;
import guoanmaker.operator.business.model.OperatorMessage;
import guoanmaker.operator.business.model.OperatorSendMesToCus;
import guoanmaker.operator.business.model.OutOperatorBoutiqueRecommend;
import guoanmaker.operator.business.service.OperatorMessageServiceIntegerface;
import guoanmaker.operator.business.service.OperatorSendMesToCusServiceIntegerface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_MESSAGE)
public class OperatorMessageController {
	@Autowired
	  private  AjaxJson ajaxJson;
	@Autowired
	private OperatorMessageServiceIntegerface operatorMessageServiceIntegerface;
	@Autowired
	private OperatorSendMesToCusServiceIntegerface operatorSendMesToCusServiceIntegerface;
	 @ApiOperation(value = "保存消息", notes = "保存消息")
	    @PostMapping(value = "saveMessage")
	    public AjaxJson saveMessage(@RequestBody OperatorMessage operatorMessage,HttpServletRequest request, HttpServletResponse response) {
		 try{
		 OperatorMessage  om=operatorMessageServiceIntegerface.saveOperatorMessage(operatorMessage, request, response);
		 ajaxJson.setSuccess(true).setStatus(200).setData(om);
		 }catch(Exception e){
			 e.printStackTrace();
			 ajaxJson.setSuccess(false).setStatus(250).setData(null);
		 }
	        return ajaxJson;
	    }
	 /**
	  * app接口
	 * @Title: getAllOperatorOperatorSendMesToCus 
	 * @Description: TODO(这里用一句话描述这个方法的作用) 
	 * @param page
	 * @param size
	 * @param phone
	 * @return    设定文件 
	 * @return AjaxJson    返回类型 
	 * @throws 
	  */
	  @ApiOperation(value = "查询消息发送列表列表", notes = "查询消息发送列表")
	    @RequestMapping(value = "/getAllOperatorOperatorSendMesToCus", method = RequestMethod.POST)
	    public AjaxJson getAllOperatorOperatorSendMesToCus(Integer page,Integer size,String phone) {
		
		  Page<OperatorSendMesToCus> ofls=operatorSendMesToCusServiceIntegerface.getOperatorSendMesToCus(page, size,phone);
	    	if(ofls.getContent().size()!=0){
	    	
	    		ajaxJson.setSuccess(true).setStatus(200).setData(ofls);
	    	}else{
	    		ajaxJson.setSuccess(false).setStatus(250).setMsg("没有数据");
	    	}
	    		
	    	
	        return ajaxJson;
	    }
	  /**
	   * app接口（pc）
	  * @Title: getMesToCus 
	  * @Description: TODO(这里用一句话描述这个方法的作用) 
	  * @param id
	  * @return    设定文件 
	  * @return AjaxJson    返回类型 
	  * @throws 
	   */
	  
	  @ApiOperation(value = "查询消息详情", notes = "查询消息详情")
	    @RequestMapping(value = "/getMesToCus", method = RequestMethod.POST)
	    public AjaxJson getMesToCus(String id) {
		
		  OperatorSendMesToCus  ofls=operatorSendMesToCusServiceIntegerface.selectSendMesToCus(id);
	    	if(ofls!=null){
	    	
	    		ajaxJson.setSuccess(true).setStatus(200).setData(ofls);
	    	}else{
	    		ajaxJson.setSuccess(false).setStatus(250).setMsg("没有数据");
	    	}
	    		
	    	
	        return ajaxJson;
	    }
	  /**
	   * app接口
	  * @Title: deleteMesToCus 
	  * @Description: TODO(这里用一句话描述这个方法的作用) 
	  * @param id
	  * @return    设定文件 
	  * @return AjaxJson    返回类型 
	  * @throws 
	   */
	  @ApiOperation(value = "删除消息", notes = "删除消息")
	    @RequestMapping(value = "/deleteMesToCus", method = RequestMethod.POST)
	    public AjaxJson deleteMesToCus(String id) {
		try{
		  operatorSendMesToCusServiceIntegerface.deleteSendMesToCusById(id);
		  ajaxJson.setSuccess(true).setStatus(200).setData(null).setMsg(null);
		}catch(Exception e){
			ajaxJson.setSuccess(false).setStatus(250).setMsg("删除失败").setData(null);
		}
	    	
	    return ajaxJson;
	    }
	  
	  
	  @ApiOperation(value = "查询消息列表pc", notes = "查询消息列表pc")
	    @RequestMapping(value = "/selectMessageList", method = RequestMethod.POST)
	    public AjaxJson selectMessageList(Integer page,Integer size) {
		try{
			Map remap=operatorMessageServiceIntegerface.selectOperatorMessageListByPage(page,size);
		  ajaxJson.setSuccess(true).setStatus(200).setData(remap);
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(250).setMsg("系统错误").setData(null);
		}
	    	
	    return ajaxJson;
	    }
	  
	  @ApiOperation(value = "查询消息详情 pc", notes = "查询消息详情pc")
	    @RequestMapping(value = "/selectMessage", method = RequestMethod.POST)
	    public AjaxJson selectMessage(String id) {
		try{
			OperatorMessage operatorMessage=operatorMessageServiceIntegerface.selectOperatorMessage(id);
		  ajaxJson.setSuccess(true).setStatus(200).setData(operatorMessage);
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(250).setMsg("系统错误").setData(null);
		}
	    	
	    return ajaxJson;
	    }
	  
	  @ApiOperation(value = "删除消息pc", notes = "删除消息pc")
	    @RequestMapping(value = "/deleteMessage", method = RequestMethod.POST)
	    public AjaxJson deleteMessage(String id) {
		try{
			operatorMessageServiceIntegerface.deleteOperatorMessage(id);
		  ajaxJson.setSuccess(true).setStatus(200).setData(null);
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(250).setMsg("系统错误").setData(null);
		}
	    	
	    return ajaxJson;
	    }
	  
	  
	  @ApiOperation(value = "查询消息发送列表列表pc官网", notes = "查询消息发送列表pc官网")
	    @RequestMapping(value = "/getAllOperatorOperatorSendMesToCusPc", method = RequestMethod.POST)
	    public AjaxJson getAllOperatorOperatorSendMesToCusPc(Integer page,Integer size,String phone,String sendStatus) {
		 
		try{
			 
			 Map remap=operatorSendMesToCusServiceIntegerface.getOperatorSendMesToCusList(page, size,phone,sendStatus);
			
		  ajaxJson.setSuccess(true).setStatus(200).setData(remap).setMsg(null);
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(250).setMsg(null);
		}
	    		
	     return ajaxJson;
	    }
	  
	  @ApiOperation(value = "查询app未读消息数量", notes = "查询app未读消息数量")
	    @RequestMapping(value = "/getNoSendMesToCusCount", method = RequestMethod.POST)
	    public AjaxJson getNoSendMesToCusCount(String phone,String sendStatus) {
		try{
			int count=0;
		  List<OperatorSendMesToCus> meses=operatorSendMesToCusServiceIntegerface.selectNoSendMesToCus(phone,sendStatus);
		  if(meses.size()>0){
			  count=meses.size();
		  }
		  ajaxJson.setSuccess(true).setStatus(200).setData(count).setMsg(null);
		}catch(Exception e){
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(250).setMsg(null);
		}
	    		
	     return ajaxJson;
	    }
	  
	  

}
